package solved;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/*
ID:		liluyan1
LANG:	JAVA
TASK:	game1
*/
public class game1 {
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new FileReader("game1.in"));
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
				"game1.out")));
		new game1().solve(f, out);
		out.close();
		System.exit(0);
	}
	
	private void solve(BufferedReader f, PrintWriter out) throws IOException {
		int N = read(f);
		int i = 0;
		int[] a = new int[N];
		String line;
		int total = 0;
		while ((line = f.readLine())!=null) {
			for (String s : line.split(" ")) {
				a[i] = Integer.parseInt(s);
				total += a[i];
				i++;
			}
		}
		
		int[][] dp = new int[N][N];
		for (int len=1; len<=N; len++) {
			for (i=0; i<=N-len; i++) {
				int p1 = a[i] + Math.min(get(dp, a, i+1, len-2), get(dp, a, i+2, len-2));
				int p2 = a[i+len-1] + Math.min(get(dp, a, i, len-2), get(dp, a, i+1, len-2));
				dp[i][len-1] = Math.max(p1, p2);
			}
		}
		
		out.println(dp[0][N-1] + " " + (total-dp[0][N-1]));
	}
	
	private int get(int[][] dp, int[] a, int i, int j) {
		if (j <= 0) return 0;
		if (j == 1) return a[i];
		return dp[i][j-1];
	}
	
	public int read(BufferedReader f) throws IOException {
		return Integer.parseInt(f.readLine());
	}
	
	public int[] read(BufferedReader f, int N) throws IOException {
		String[] t = f.readLine().split(" ");
		int[] a = new int[N];
		for (int i=0; i<N; i++) {
			a[i] = Integer.parseInt(t[i]);
		}
		return a;
	}
}
